package Thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/*
    线程池的基本使用:
    static public ExecutorsService newFixedThreadPool(int nThreads):创建一个指定数量的线程池对象
    调用ExecutorsService对象的submit(Runnable task)来执行run方法
    shutdown()：关闭线程池

 */
public class ExecutorsDemo {
    public static void main(String[] args) {
        ExecutorService executorService= Executors.newFixedThreadPool(2);   //创建2个线程的线程池对象
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println("i:"+i);
                }
            }
        });
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println("J:"+i);
                }
            }
        });
    }
}
